package com.atguigu.cloud.resp;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * ClassName:    ResultData
 * Package:  com.atguigu.cloud.resp
 * Description:
 *
 * @Author: interface
 * @Create: 2025/7/16 - 上午3:36
 * @Version: v1.0
 */
@Data
@Accessors(chain = true)
public class ResultData<T> {
    private String code;
    private String msg;
    private T data;
    private long timestamp;

    public ResultData() {
        this.timestamp = System.currentTimeMillis();
    }

    public  static <T> ResultData<T> success(T data) {
        ResultData resultData = new ResultData();
        resultData.setCode(ResultCodeEnum.RC200.getCode());
        resultData.setMsg(ResultCodeEnum.RC200.getMessage());
        resultData.setData(data);

        return resultData;
    }

    public  static <T> ResultData<T> error(String code,String message) {
        ResultData resultData = new ResultData();
        resultData.setCode(code);
        resultData.setMsg(message);
        resultData.setData(null);
        return resultData;
    }

    public  static <T> ResultData<T> error(String message) {
        ResultData resultData = new ResultData();
        resultData.setCode(ResultCodeEnum.RC500.getCode());
        resultData.setMsg(message);
        resultData.setData(null);
        return resultData;
    }
}
